<?php
/**
 * Autor:   Miguel A. Zilli
 * Email:   miguelzilli@gmail.com
 */

class Departamento extends AppModel {
    var $name = 'Departamento';
    var $useTable = 'departamentos';
    var $primaryKey = 'id';
    var $displayField = 'nombre_dpto';
    var $recursive = 0;
    var $order=array(
        'Departamento.nombre_dpto'=>'ASC'
    );

    var $validate = array(
        'nombre_dpto'  =>array(
            array('rule'=>'notEmpty','message'=>'Debe completar este dato.')
        )
    );

    //The Associations below have been created with all possible keys, those that are not needed can be removed
    var $belongsTo = array(
        'Provincia' => array(
            'className' => 'Provincia',
            'foreignKey' => 'provincia_id'
        )
    );

    var $hasMany = array(
        'Localidad' => array(
            'className' => 'Localidad',
            'foreignKey' => 'departamento_id',
            'dependent' => false
        )
    );

    public function beforeSave(){
        if(!empty($this->data['Departamento'])){
            foreach($this->data['Departamento'] as $campo=>$valor){
                $this->data['Departamento'][$campo]=strtoupper($valor);
            }
        }
        return true;
    }
}
?>